/**
 * @author Tobias Boehm
 *
 * 06.06.2011
 */
package org.anddev.andengine.extension.tbsengine.message.client;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;

import org.anddev.andengine.extension.tbsengine.match.AbsClientMatch;
import org.anddev.andengine.extension.tbsengine.match.AbsServerMatch;
import org.anddev.andengine.extension.tbsengine.match.AbsServerMatchPreparation;
import org.anddev.andengine.extension.tbsengine.message.client.preparematch.AbsClientSlotChangeRequestMessage;

/**
 * This is an abstract class for client messages which are related to an
 * instance of an implementation of {@link AbsServerMatchPreparation} or
 * {@link AbsServerMatch}.
 * <p>
 * You should extend from this class if you want to develop new match related
 * messages. For player slot related messages use {@link AbsClientSlotChangeRequestMessage}
 * instead.
 * 
 * @author Tobias Boehm
 *
 */
public abstract class AbsClientMatchMessage extends AbsClientMessage {

	protected UUID mMatchID = null;
	
	protected abstract void onReadTransmissionClientMatchData(final DataInputStream pDataInputStream) throws IOException;
	protected abstract void onWriteTransmissionClientMatchData(final DataOutputStream pDataOutputStream) throws IOException;
	
	
	@Override
	protected void onReadTransmissionClientData(DataInputStream pDataInputStream)
			throws IOException {
		
			this.mMatchID = UUID.fromString(pDataInputStream.readUTF());
			
			this.onReadTransmissionClientMatchData(pDataInputStream);
	}

	@Override
	protected void onWriteTransmissionClientData(
			DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeUTF(this.mMatchID.toString());
		
		this.onWriteTransmissionClientMatchData(pDataOutputStream);
	}

	public void setMatch(AbsClientMatch pMatch){
		
		this.mMatchID = pMatch.getMatchID();
	}

	/**
	 * @return the mMatchID
	 */
	public UUID getMatchID() {
		return mMatchID;
	}
	
}
